package com.sample.tdf.service.impl;

import cn.com.taiji.common.base.BaseServiceImpl;
import com.sample.tdf.domain.Employee;
import com.sample.tdf.domain.EmployeeRepository;
import com.sample.tdf.domain.Student;
import com.sample.tdf.domain.StudentRepository;
import com.sample.tdf.dto.EmployeeDTO;
import com.sample.tdf.dto.StudentDTO;
import com.sample.tdf.exception.TDFSampleException;
import com.sample.tdf.service.IEmployeeService;
import com.sample.tdf.service.IStudentService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class EmployeeServiceImpl extends BaseServiceImpl<EmployeeRepository, Employee, EmployeeDTO> implements IEmployeeService {

    @Override
    public EmployeeDTO beforeCreate(EmployeeDTO dto) {
        if (StringUtils.isEmpty(dto.getJobNumber())){
            throw new TDFSampleException("员工的工号不能为空");
        }
        if (StringUtils.isEmpty(dto.getEmployeeName())) {
            throw new TDFSampleException("员工姓名不能为空");
        }
        if (StringUtils.isEmpty(dto.getEmployeeSex())) {
            throw new TDFSampleException("员工性别不能为空");
        }
        if (StringUtils.isEmpty(dto.getDepartmentId())){
            throw new TDFSampleException("员工的部门ID不能为空");
        }
        if (StringUtils.isEmpty(dto.getDepartmentName())) {
            throw new TDFSampleException("员工部门名称不能为空");
        }
        return super.beforeCreate(dto);
    }

    @Override
    public List<EmployeeDTO> findByDepartmentName(String departmentName) {
        List<Employee> listEmployee =  iBaseRepository.findByDepartmentName(departmentName);
        return domainListToDTOList(listEmployee);
    }
}
